package com.pucong.gitee.database.backup.database.controller;

import com.pucong.gitee.database.backup.database.service.OperationDataSchemaService;
import com.pucong.gitee.database.backup.database.vo.DeleteDataSchema;
import com.pucong.gitee.database.backup.database.vo.RenameDataSchema;
import com.pucong.gitee.database.backup.utils.Res;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author pucong
 * @company www.louddt.com
 * @create 2020-06-23
 */
@RestController
@RequestMapping("/operation/dataSchema")
@Api(value = "数据模式操作-API ", tags = "4. 数据模式操作 API")
public class OperationDataSchemaController {

    @Autowired
    private OperationDataSchemaService operationDataSchemaService;

    @GetMapping("/getSchemaList/{databaseId}")
    @ApiOperation(value = "401根据数据库id获取模式list")
    public Res<List<String>> getSchemaList(@ApiParam("数据库id")@PathVariable("databaseId") String databaseId,@ApiParam("数据库名称")@RequestParam("databaseName") String databaseName){
        List<String> schemaList = operationDataSchemaService.getSchemaList(databaseId, databaseName);
        return Res.ok(schemaList);
    }

    @PostMapping("/renameDataSchema/{databaseId}")
    @ApiOperation(value = "402根据数据库id和数据库名称删除模式")
    public Res<Boolean> renameDataSchema(@ApiParam("数据库id")@PathVariable("databaseId") String databaseId,@RequestBody RenameDataSchema renameDataSchema){
        Boolean aBoolean = operationDataSchemaService.renameDataSchema(databaseId, renameDataSchema);
        return Res.ok(aBoolean);
    }

    @DeleteMapping("/deleteDataSchema/{databaseId}")
    @ApiOperation(value = "403根据数据库id和数据库名称删除模式")
    public Res<Boolean> deleteDataSchema(@ApiParam("数据库id")@PathVariable("databaseId") String databaseId, @ApiParam("数据库id") @RequestBody DeleteDataSchema deleteDataSchema){
        Boolean aBoolean = operationDataSchemaService.deleteDataSchema(databaseId, deleteDataSchema);
        return Res.ok(aBoolean);
    }

}
